package com.jiantong.work.impl.service.yangzhibaoxian;

/**
 * Created by ThinkPad on 2017/9/5.
 */

import com.google.common.base.Throwables;
import com.jiantong.work.impl.dao.yangzhibaoxian.HarmlessConductDao;
import com.jiantong.work.model.yangzhibaoxian.File;
import com.jiantong.work.model.yangzhibaoxian.HarmlessConduct;
import com.jiantong.work.service.yangzhibaoxian.HarmlessConductService;
import io.terminus.boot.rpc.common.annotation.RpcProvider;
import io.terminus.common.model.PageInfo;
import io.terminus.common.model.Paging;
import io.terminus.common.model.Response;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * 无害化处理表
 */
@Slf4j
@Service
@RpcProvider
public class HarmlessConductServiceImpl implements HarmlessConductService{
    private HarmlessConductDao harmlessConductDao;

    @Autowired
    public HarmlessConductServiceImpl(HarmlessConductDao harmlessConductDao) {
        this.harmlessConductDao = harmlessConductDao;
    }

    @Override
    public Response<HarmlessConduct> findById(Long id) {
        try {
            HarmlessConduct harmlessConduct = (HarmlessConduct)  harmlessConductDao.findById(id);
            if (harmlessConduct == null) {
                log.error("harmlessConduct(id={}) is not found", id);
                return Response.fail("harmlessConduct.not.found");
            }

            return Response.ok(harmlessConduct);
        } catch (Exception e) {
            log.error("failed to find harmlessConduct(id={}), cause:{}", id, Throwables.getStackTraceAsString(e));
            return Response.fail("harmlessConduct.find.fail");
        }
    }

    @Override
    public Response<List<HarmlessConduct>> findByIds(List ids) {
        try {
            List<HarmlessConduct> harmlessConductList =  harmlessConductDao.findByIds(ids);
            if (harmlessConductList == null) {
                log.error("harmlessConductList(ids={}) is not found", ids);
                return Response.fail("harmlessConductList.not.found");
            }

            return Response.ok(harmlessConductList);
        } catch (Exception e) {
            log.error("failed to find harmlessConductList(ids={}), cause:{}", ids, Throwables.getStackTraceAsString(e));
            return Response.fail("harmlessConductList.find.fail");
        }

    }

    @Override
    public Response<List<HarmlessConduct>> list(Map map) {
        try {
            List<HarmlessConduct> harmlessConductList =  harmlessConductDao.list(map);
            if (harmlessConductList == null) {
                log.error("harmlessConductList(ids={}) is not found", map);
                return Response.fail("harmlessConductList.not.found");
            }

            return Response.ok(harmlessConductList);
        } catch (Exception e) {
            log.error("failed to find harmlessConductList(ids={}), cause:{}", map, Throwables.getStackTraceAsString(e));
            return Response.fail("harmlessConductList.find.fail");
        }
    }

    @Override
    public Response<Paging<HarmlessConduct>> ping(Integer offset, Integer limit, Map map) {
        try {
            PageInfo pageInfo=new PageInfo(offset,limit);
            Paging<HarmlessConduct> harmlessConductPaging =  harmlessConductDao.paging(pageInfo.getOffset(),pageInfo.getLimit(), map);
            if (harmlessConductPaging == null) {
                log.error("harmlessConductPaging(ids={}) is not found", map);
                return Response.fail("harmlessConductPaging.not.found");
            }

            return Response.ok(harmlessConductPaging);
        } catch (Exception e) {
            log.error("failed to find harmlessConductPaging(ids={}), cause:{}", map, Throwables.getStackTraceAsString(e));
            return Response.fail("harmlessConductPaging.find.fail");
        }
    }

    @Override
    public Boolean update(HarmlessConduct harmlessConduct) {
        try {
            Boolean b =  harmlessConductDao.update(harmlessConduct);
            return b;
        } catch (Exception e) {
            return false;
        }
    }

    @Override
    public Long create(HarmlessConduct harmlessConduct) {
        try {
            harmlessConductDao.create(harmlessConduct);
            return harmlessConduct.getId();
        } catch (Exception e) {
            e.printStackTrace();
            return -500L;
        }
    }

    @Override
    public Integer creates(List<HarmlessConduct> harmlessConductList) {
        try {

            return  harmlessConductDao.creates(harmlessConductList);
        } catch (Exception e) {
            e.printStackTrace();
            return -500;
        }
    }

    @Override
    public HarmlessConduct findByClaimsId(Long claims_settlement_id) {
        return harmlessConductDao.findByClaimsId(claims_settlement_id);
    }
}
